package com.test.controller;

import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;


/**
 * 全局数据绑定处理，将会应用到所有Controller
 *
 */
@ControllerAdvice
public class GlobalBinderController {

	@InitBinder
	public void initBinder(WebDataBinder binder) {
		// 统一去除前后空格Editor，如果空串时会设置为null
		binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
		// util的Date类型
		binder.registerCustomEditor(java.util.Date.class, new SqlDateEditor());
	}
}

